package com.ls.thread.ch04.demo01;

public class TicketThread extends Thread{
	
	//动态的 每次new会创建
//	private int ticket=10;
	
	//静态的只会产生一个这样的资源，用来共享
	private   int ticket=10;
	
	
	
	@SuppressWarnings("static-access")
	@Override
	public void run() {
		
		while(ticket>0){
			
			synchronized (TicketRunnable.class) {
				
				System.out.println(this.getName()+"卖出第"+ticket+"张票，现在还有"+(ticket-1));
				ticket=ticket-1;
			}
			try {
				Thread.currentThread().sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
		}
	}

}
